home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.do_name.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  279 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.do_name.c version 1.0.1 - correction in call of xname() */
  3.  
  4. #include "hack.h"
  5. #include <stdio.h>
  6.  
  7. extern int mousex;
  8. extern int mousey;
  9.  
  10. coord
  11. getpos(force,goal) int force; char *goal; {
  12. register int cx,cy,i,c;
  13. extern char sdir[];      /* defined in hack.c */
  14. extern schar xdir[], ydir[];   /* idem */
  15. extern char *visctrl();      /* see below */
  16. coord cc;
  17.    pline("(For instructions type a ?)");
  18.    cx = u.ux;
  19.    cy = u.uy;
  20.    curs(cx,cy+2);
  21.    while((c = readchar()) != '.'){
  22.       for(i=0; i<8; i++) if(sdir[i] == c){
  23.          if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
  24.             cx += xdir[i];
  25.          if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1)
  26.             cy += ydir[i];
  27.          goto nxtc;
  28.       }
  29.       if(c == '?'){
  30.          pline("Use [hjkl] to move the cursor to %s.", goal);
  31.          pline("Type a . when you are at the right place.");
  32.       } else if (c == MDOWN) {
  33.     cx = mousex;
  34.     cy = mousey-2;
  35.     } else if (c == MUP) {
  36.     cx = mousex;
  37.     cy = mousey-2;
  38.     break;
  39.     } else {
  40.          pline("unknown direction: '%s' (%s)",
  41.             visctrl(c),
  42.             force ? "use hjkl or ." : "aborted");
  43.          if(force) goto nxtc;
  44.          cc.x = -1;
  45.          cc.y = 0;
  46.          return(cc);
  47.       }
  48.    nxtc:   ;
  49.       curs(cx,cy+2);
  50.    }
  51.    cc.x = cx;
  52.    cc.y = cy;
  53.    return(cc);
  54. }
  55.  
  56. do_mname(){
  57. char buf[BUFSZ];
  58. coord cc;
  59. register int cx,cy,lth,i;
  60. register struct monst *mtmp, *mtmp2;
  61. extern char *lmonnam();
  62.    cc = getpos(0, "the monster you want to name");
  63.    cx = cc.x;
  64.    cy = cc.y;
  65.    if(cx < 0) return(0);
  66.    mtmp = m_at(cx,cy);
  67.    if(!mtmp){
  68.        if(cx == u.ux && cy == u.uy){
  69.       extern char plname[];
  70.       pline("This ugly monster is called %s and cannot be renamed.",
  71.           plname);
  72.        } else   pline("There is no monster there.");
  73.        return(1);
  74.    }
  75.    if(mtmp->mimic){
  76.        pline("I see no monster there.");
  77.        return(1);
  78.    }
  79.    if(!cansee(cx,cy)) {
  80.        pline("I cannot see a monster there.");
  81.        return(1);
  82.    }
  83.    pline("What do you want to call %s? ", lmonnam(mtmp));
  84.    getlin(buf);
  85.    clrlin();
  86.    if(!*buf) return(1);
  87.    lth = strlen(buf)+1;
  88.    if(lth > 63){
  89.       buf[62] = 0;
  90.       lth = 63;
  91.    }
  92.    mtmp2 = newmonst(mtmp->mxlth + lth);
  93.    *mtmp2 = *mtmp;
  94.    for(i=0; i<mtmp->mxlth; i++)
  95.       ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
  96.    mtmp2->mnamelth = lth;
  97.    (void) strcpy(NAME(mtmp2), buf);
  98.    replmon(mtmp,mtmp2);
  99.    if(mtmp2->isshk) setshk();   /* redefine shopkeeper and bill */
  100.    if(mtmp2->isgd) setgd( /* mtmp2 */ );
  101.    return(1);
  102. }
  103.  
  104. /*
  105.  * This routine changes the address of  obj . Be careful not to call it
  106.  * when there might be pointers around in unknown places. For now: only
  107.  * when  obj  is in the inventory.
  108.  */
  109. do_oname(obj) register struct obj *obj; {
  110. register struct obj *otmp, *otmp2;
  111. register int lth;
  112. char buf[BUFSZ];
  113.    pline("What do you want to name %s? ", doname(obj));
  114.    getlin(buf);
  115.    clrlin();
  116.    if(!*buf) return;
  117.    lth = strlen(buf)+1;
  118.    if(lth > 63){
  119.       buf[62] = 0;
  120.       lth = 63;
  121.    }
  122.    otmp2 = newobj(lth);
  123.    *otmp2 = *obj;
  124.    otmp2->onamelth = lth;
  125.    (void) strcpy(ONAME(otmp2), buf);
  126.  
  127.    setworn((struct obj *) 0, obj->owornmask);
  128.    setworn(otmp2, otmp2->owornmask);
  129.  
  130.    /* do freeinv(obj); etc. by hand in order to preserve
  131.       the position of this object in the inventory */
  132.    if(obj == invent) invent = otmp2;
  133.    else for(otmp = invent; ; otmp = otmp->nobj){
  134.       if(!otmp)
  135.          panic("Do_oname: cannot find obj.");
  136.       if(otmp->nobj == obj){
  137.          otmp->nobj = otmp2;
  138.          break;
  139.       }
  140.    }
  141.    /* obfree(obj, otmp2);   /* now unnecessary: no pointers on bill */
  142.    free((char *) obj);   /* let us hope nobody else saved a pointer */
  143. }
  144.  
  145. ddocall()
  146. {
  147.    register struct obj *obj;
  148.  
  149.    pline("Do you want to name an individual object? [yn] ");
  150.    if(readchar() == 'y'){
  151.       obj = getobj("#", "name");
  152.       if(obj) do_oname(obj);
  153.    } else {
  154.       obj = getobj("?!=/", "call");
  155.       if(obj) docall(obj);
  156.    }
  157.    return(0);
  158. }
  159.  
  160. docall(obj)
  161. register struct obj *obj;
  162. {
  163.    char buf[BUFSZ];
  164.    register char **str1;
  165.    extern char *xname();
  166.     struct obj otemp;
  167.    register char *str;
  168.  
  169.     otemp = *obj;
  170.     otemp.quan = 1;
  171.     str = xname(&otemp);
  172.    pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str);
  173.    getlin(buf);
  174.    clrlin();
  175.    if(!*buf) return;
  176.    str = newstring(strlen(buf)+1);
  177.    (void) strcpy(str,buf);
  178.    str1 = &(objects[obj->otyp].oc_uname);
  179.    if(*str1) free(*str1);
  180.    *str1 = str;
  181. }
  182.  
  183. char *
  184. xmonnam(mtmp, vb) register struct monst *mtmp; int vb; {
  185. static char buf[BUFSZ];      /* %% */
  186. extern char *shkname();
  187.     if(mtmp->mnamelth && !vb) {
  188.         (void) strcpy(buf, NAME(mtmp));
  189.         return(buf);
  190.     }
  191.    switch(mtmp->data->mlet) {
  192.    case ' ':
  193.       (void) sprintf(buf, "%s's ghost", (char *) mtmp->mextra);
  194.       break;
  195.    case '@':
  196.       if(mtmp->isshk) {
  197.          (void) strcpy(buf, shkname());
  198.          break;
  199.       }
  200.       /* fall into next case */
  201.    default:
  202.       (void) sprintf(buf, "the %s%s",
  203.          mtmp->minvis ? "invisible " : "",
  204.          mtmp->data->mname);
  205.    }
  206.    if(vb && mtmp->mnamelth) {
  207.       (void) strcat(buf, " called ");
  208.       (void) strcat(buf, NAME(mtmp));
  209.    }
  210.    return(buf);
  211. }
  212.  
  213. char *
  214. lmonnam(mtmp) register struct monst *mtmp; {
  215.    return(xmonnam(mtmp, 1));
  216. }
  217.  
  218. char *
  219. monnam(mtmp) register struct monst *mtmp; {
  220.    return(xmonnam(mtmp, 0));
  221. }
  222.  
  223. char *
  224. Monnam(mtmp) register struct monst *mtmp; {
  225. register char *bp = monnam(mtmp);
  226.    if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a');
  227.    return(bp);
  228. }
  229.  
  230. char *
  231. amonnam(mtmp,adj)
  232. register struct monst *mtmp;
  233. register char *adj;
  234. {
  235.    register char *bp = monnam(mtmp);
  236.    static char buf[BUFSZ];      /* %% */
  237.  
  238.    if(!strncmp(bp, "the ", 4)) bp += 4;
  239.    (void) sprintf(buf, "the %s %s", adj, bp);
  240.    return(buf);
  241. }
  242.  
  243. char *
  244. Amonnam(mtmp, adj)
  245. register struct monst *mtmp;
  246. register char *adj;
  247. {
  248.    register char *bp = amonnam(mtmp,adj);
  249.  
  250.    *bp = 'T';
  251.    return(bp);
  252. }
  253.  
  254. char *
  255. Xmonnam(mtmp) register struct monst *mtmp; {
  256. register char *bp = Monnam(mtmp);
  257.    if(!strncmp(bp, "The ", 4)) {
  258.       bp += 2;
  259.       *bp = 'A';
  260.    }
  261.    return(bp);
  262. }
  263.  
  264. char *
  265. visctrl(c)
  266. char c;
  267. {
  268. static char ccc[3];
  269.    if(c < 040) {
  270.       ccc[0] = '^';
  271.       ccc[1] = c + 0100;
  272.       ccc[2] = 0;
  273.    } else {
  274.       ccc[0] = c;
  275.       ccc[1] = 0;
  276.    }
  277.    return(ccc);
  278. }
  279.